package session07.homework;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TopPanel extends JPanel {

    private JLabel imgLab;

    private JPanel midLab;
    private JComboBox<String> qqComb;
    private JComboBox<String> applyqqComb;
    private JLabel txtLab1;
    private JLabel txtLab2;
    private JPasswordField pwdTxt;//密码框
    private JLabel txtLab3;
    private JCheckBox autoLogin;
    private JCheckBox hideLogin;

    private JPanel botLab;
    private JButton check;
    private JButton set;
    private JLabel temp;
    private JButton login;

   /* private MyFrame myFrame;*/

    public TopPanel(MyFrame myFrame) {
        //this.myFrame = myFrame;

        //上面
        this.setLayout(new BorderLayout());
        this.imgLab = new JLabel();
        this.imgLab.setIcon(new ImageIcon("img/title.jpg"));
        this.add(this.imgLab, BorderLayout.NORTH);

        //中间
        this.midLab = new JPanel();
        this.midLab.setLayout(null);
        this.qqComb = new JComboBox<>();
        this.applyqqComb = new JComboBox<>();

        this.qqComb.addItem("QQ号码  ");
        this.qqComb.setBounds(10, 10, 80, 20);
        this.midLab.add(this.qqComb);

        this.applyqqComb.setBounds(100, 10, 120, 20);
        this.applyqqComb.setEditable(true);
        this.midLab.add(this.applyqqComb);

        this.txtLab1 = new JLabel();
        this.txtLab1.setText("申请号码");
        this.txtLab1.setBounds(230, 10, 100, 20);
        this.midLab.add(this.txtLab1);

        this.txtLab2 = new JLabel();
        this.txtLab2.setText("QQ密码");
        this.txtLab2.setBounds(10, 40, 100, 20);
        this.midLab.add(this.txtLab2);

        this.pwdTxt = new JPasswordField();
        this.pwdTxt.setBounds(100, 40, 120, 20);
        this.midLab.add(this.pwdTxt);

        this.txtLab3 = new JLabel();
        this.txtLab3.setText("忘了密码？");
        this.txtLab3.setBounds(230, 40, 100, 20);
        this.midLab.add(this.txtLab3);

        this.autoLogin = new JCheckBox();
        this.autoLogin.setText("自动登陆");
        this.hideLogin = new JCheckBox();
        this.hideLogin.setText("隐身登陆");
        this.autoLogin.setBounds(90, 70, 80, 20);
        this.hideLogin.setBounds(180, 70, 80, 20);
        this.midLab.add(this.autoLogin);
        this.midLab.add(this.hideLogin);
        this.midLab.setBackground(new Color(243, 248, 252));

        this.add(this.midLab);

        //下面
        this.botLab = new JPanel();
        this.check = new JButton("安全检查");
        this.botLab.add(this.check);
        this.set = new JButton("设置↑");
        this.botLab.add(this.set);
        this.temp = new JLabel("            ");
        this.botLab.add(this.temp);
        this.login = new JButton("登陆");
        this.botLab.add(this.login);
        this.botLab.setBackground(new Color(225, 249, 255));

        this.add(this.botLab, BorderLayout.SOUTH);

        this.set.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (TopPanel.this.set.getText().equals("设置↑")) {
                    myFrame.setSize(338, 255);
                    TopPanel.this.set.setText("设置↓");
                } else if (TopPanel.this.set.getText().equals("设置↓")) {
                    //TopPanel.this.myFrame.setSize(338, 587);不需要，因为myFrame是引用类型，修改的引用对象里的值
                    myFrame.setSize(338, 587);
                    TopPanel.this.set.setText("设置↑");
                }
            }
        });
    }
}
